<%--
  Created by IntelliJ IDEA.
  User: kingshion
  Date: 2020/5/23
  Time: 22:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改题目</title>
    <script src="../../layui/layui.js"></script>
    <link rel="stylesheet" href="../../layui/css/layui.css">
</head>
<body>
<br>
<h3 style="margin-left: 30px">题目管理</h3>
<br>
<hr>
<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">题型</label>
        <div class="layui-input-inline">
            <select name="question_type" id="question_type" lay-filter="question_type">
                <option value=""></option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">题库</label>
        <div class="layui-input-inline layui-form" lay-filter="course_name">
            <select id="course_name" lay-filter="coures" lay-verify="required"></select>
        </div>
    </div>

    <div class="layui-inline">
        <label class="layui-form-label">题干</label>
    </div>
    <div class="layui-form-item" style="width: 700px ;margin-left: 100px">
        <textarea id="content"></textarea>
    </div>

    <div class="layui-inline">
        <label class="layui-form-label">选项A</label>
    </div>
    <div class="layui-form-item" style="width: 700px ;margin-left: 100px">
        <textarea id="optionA"></textarea>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">选项B</label>
    </div>
    <div class="layui-form-item" style="width: 700px ;margin-left: 100px">
        <textarea id="optionB"></textarea>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">选项C</label>
    </div>
    <div class="layui-form-item" style="width: 700px ;margin-left: 100px">
        <textarea id="optionC"></textarea>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">选项D</label>
    </div>
    <div class="layui-form-item" style="width: 700px ;margin-left: 100px">
        <textarea id="optionD"></textarea>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">答案</label>
    </div>
    <div class="layui-form-item" style="width: 700px ;margin-left: 100px">
        <textarea id="answer"></textarea>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit id="updateBtn" lay-filter="updateQuestion">修改</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>

<script>
    layui.use(['layer', 'table', 'element', 'form', 'layedit'], function () {
        var layer = layui.layer,
            table = layui.table,
            $ = layui.jquery,
            form = layui.form,
            layedit = layui.layedit,
            element = layui.element;

        // 动态渲染题库的下拉框选项
        $.ajax({
            url: "/OnlineExam/admin/course?m=showCourseNames",
            success: function (result) {
                console.log(result);
                var names = $.parseJSON(result);
                var option = '';
                for (let i = 0; i < names.length; i++) {
                    console.log(names[i])
                    option += "<option value='" + names[i] + "'>" + names[i] + "</option>";

                    $("#course_name").html("");
                    $("#course_name").append(option);
                    form.render('select', 'course_name');
                }

            }
        });

        // 富文本编辑器的设置
        var content = layedit.build('content', {
            height: 100 //设置编辑器高度
        }); //建立编辑器

        var optionA = layedit.build('optionA', {
            height: 50 //设置编辑器高度
        }); //建立编辑器

        var optionB = layedit.build('optionB', {
            height: 50 //设置编辑器高度
        }); //建立编辑器

        var optionC = layedit.build('optionC', {
            height: 50 //设置编辑器高度
        }); //建立编辑器

        var optionD = layedit.build('optionD', {
            height: 50 //设置编辑器高度
        }); //建立编辑器

        var answer = layedit.build('answer', {
            height: 80 //设置编辑器高度
        }); //建立编辑器

        // 监听提交按钮
        /*form.on('submit(updateQuestion)', function (data) {
            // 得到多选框的值
            var type = document.getElementById("question_type");
            var index = type.selectedIndex; // 选中索引
            var typeValue = type.options[index].value; // 选中值

            console.log(typeValue);

            var course = document.getElementById("course_name");
            var c_index = course.selectedIndex;
            var courseValue = course.options[c_index].value;
            console.log(courseValue);

            var contentText = layedit.getText(content);//取纯文本值
            var optionAText = layedit.getText(optionA);
            var optionBText = layedit.getText(optionB);
            var optionCText = layedit.getText(optionC);
            var optionDText = layedit.getText(optionD);
            var answerText = layedit.getText(answer);

            console.log(contentText + "-->" + optionAText);

            // console.log(type+'--'+course+'--'+content+'--'+optionA+'--'+optionB+'--'+optionC+'---'+optionD+'--'+answer);

           /!* $.ajax({
                url: "/OnlineExam/admin/question?m=add",
                method:"post",
                data: "course=" + courseValue + "&type=" + typeValue + "&user_id=" + 100005 + "&content=" + contentText + "&optionA=" + optionAText + "&optionB=" + optionBText + "&optionC=" + optionCText + "&optionD=" + optionDText + "&answer=" + answerText,
                success: function (result) {
                    layer.msg("添加成功");
                }
            });*!/
            return false;
        })*/
    })

</script>
</html>
